package com.suse.lhw.hms.authserver.handler;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.hms.authserver.config
 * @ClassName: RestAccessDeniedHandler
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/4/5 14:10
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/4/5 14:10
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Component
public class RestAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {

        System.out.println("RestAccessDeniedHandler:" + e.getMessage());
        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "拒绝访问");
    }
}
